var box=$('#box')

function showAllHolidayInformationRule(){
    $.ajax({
        url:'/admin/showAllStuRecord',
        data:$('form').serialize(),
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].name}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><span class="badge bg-success">${res[i].type}</span></td>
                      <td><span class="badge bg-success">${res[i].addr}</span></td>
                      <td><span class="badge bg-success">${res[i].beginTime}</span></td>
                      <td><span class="badge bg-success">${res[i].endTime}</span></td>
                      <td><span class="badge bg-success">${res[i].contact1}</span></td>
                      <td><span class="badge bg-danger" >${res[i].contact2}</span></td>
                      <td><span class="badge bg-danger" >${res[i].traffic}</span></td>
                    </tr>
                `
            }
            box.html(`
                <form onsubmit="return false">
                    <div class="nav">
                        <input name="holiday" type="text" class="nav-item" placeholder="假期">&nbsp;&nbsp;&nbsp;&nbsp;
                        <select name="type" type="text" class="nav-item">
                            <option>离校</option>
                            <option>不离校</option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="addr" type="text" class="nav-item" placeholder="地址">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="beginTime" type="date" class="nav-item" placeholder="开始时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="endTime" type="date" class="nav-item" placeholder="结束时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="traffic" type="text" class="nav-item" placeholder="交通方式">&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="height: 20px"></div>
                    <input onclick="showHolidayInformationRule()" style="border-radius: 3px" type="submit" class="btn-info" value="提交">
                </form>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>学生账号</th>
                      <th>假期</th>
                      <th>是否离校</th>
                      <th>地址</th>
                      <th>离校时间</th>
                      <th>返校时间</th>
                      <th>联系人一</th>
                      <th>联系人二</th>
                      <th>交通方式</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}
function showAllStuRecord() {
    $.ajax({
        url:'/admin/showAllStuRecord',
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].name}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><span class="badge bg-success">${res[i].type}</span></td>
                      <td><span class="badge bg-success">${res[i].addr}</span></td>
                      <td><span class="badge bg-success">${res[i].beginTime}</span></td>
                      <td><span class="badge bg-success">${res[i].endTime}</span></td>
                      <td><span class="badge bg-success">${res[i].contact1}</span></td>
                      <td><span class="badge bg-danger" >${res[i].contact2}</span></td>
                      <td><span class="badge bg-danger" >${res[i].traffic}</span></td>
                    </tr>
                `
            }
            box.html(`
                <form onsubmit="return false">
                    <div class="nav">
                        <input name="holiday" type="text" class="nav-item" placeholder="假期">&nbsp;&nbsp;&nbsp;&nbsp;
                        <select name="type" type="text" class="nav-item">
                            <option>离校</option>
                            <option>不离校</option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="addr" type="text" class="nav-item" placeholder="地址">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="beginTime" type="date" class="nav-item" placeholder="开始时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="endTime" type="date" class="nav-item" placeholder="结束时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="traffic" type="text" class="nav-item" placeholder="交通方式">&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="height: 20px"></div>
                    <input onclick="showAllHolidayInformationRule()" style="border-radius: 3px" type="submit" class="btn-info" value="提交">
                </form>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>学生账号</th>
                      <th>假期</th>
                      <th>是否离校</th>
                      <th>地址</th>
                      <th>离校时间</th>
                      <th>返校时间</th>
                      <th>联系人一</th>
                      <th>联系人二</th>
                      <th>交通方式</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}
function showHolidayInformationRule(){
    $.ajax({
        url:'/admin/showNowStuRecord',
        data:$('form').serialize(),
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].name}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><span class="badge bg-success">${res[i].type}</span></td>
                      <td><span class="badge bg-success">${res[i].addr}</span></td>
                      <td><span class="badge bg-success">${res[i].beginTime}</span></td>
                      <td><span class="badge bg-success">${res[i].endTime}</span></td>
                      <td><span class="badge bg-success">${res[i].contact1}</span></td>
                      <td><span class="badge bg-danger" >${res[i].contact2}</span></td>
                      <td><span class="badge bg-danger" >${res[i].traffic}</span></td>
                    </tr>
                `
            }
            box.html(`
                <form onsubmit="return false">
                    <div class="nav">
                        <input name="holiday" type="text" class="nav-item" placeholder="假期">&nbsp;&nbsp;&nbsp;&nbsp;
                        <select name="type" type="text" class="nav-item">
                            <option>离校</option>
                            <option>不离校</option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="addr" type="text" class="nav-item" placeholder="地址">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="beginTime" type="date" class="nav-item" placeholder="开始时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="endTime" type="date" class="nav-item" placeholder="结束时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="traffic" type="text" class="nav-item" placeholder="交通方式">&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="height: 20px"></div>
                    <input onclick="showHolidayInformationRule()" style="border-radius: 3px" type="submit" class="btn-info" value="提交">
                </form>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>学生账号</th>
                      <th>假期</th>
                      <th>是否离校</th>
                      <th>地址</th>
                      <th>离校时间</th>
                      <th>返校时间</th>
                      <th>联系人一</th>
                      <th>联系人二</th>
                      <th>交通方式</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}
function showNowStuRecord(id) {
    console.log("id:"+id)
    if (id==null){
        box.html('貌似当前没有假期记录需要填写~~~')
    }else{
        $.ajax({
            url:'/admin/showNowStuRecord',
            success:function (res) {
                let tbody=``;
                for (let i=0;i<res.length;i++){
                    tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].name}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><span class="badge bg-success">${res[i].type}</span></td>
                      <td><span class="badge bg-success">${res[i].addr}</span></td>
                      <td><span class="badge bg-success">${res[i].beginTime}</span></td>
                      <td><span class="badge bg-success">${res[i].endTime}</span></td>
                      <td><span class="badge bg-success">${res[i].contact1}</span></td>
                      <td><span class="badge bg-danger" >${res[i].contact2}</span></td>
                      <td><span class="badge bg-danger" >${res[i].traffic}</span></td>
                    </tr>
                `
                }
                box.html(`
                <form onsubmit="return false">
                    <div class="nav">
                        <input name="holiday" type="text" class="nav-item" placeholder="假期">&nbsp;&nbsp;&nbsp;&nbsp;
                        <select name="type" type="text" class="nav-item">
                            <option>离校</option>
                            <option>不离校</option>
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="addr" type="text" class="nav-item" placeholder="地址">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="beginTime" type="date" class="nav-item" placeholder="开始时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="endTime" type="date" class="nav-item" placeholder="结束时间">&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="traffic" type="text" class="nav-item" placeholder="交通方式">&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                    <div style="height: 20px"></div>
                    <input onclick="showHolidayInformationRule()" style="border-radius: 3px" type="submit" class="btn-info" value="提交">
                </form>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>学生账号</th>
                      <th>假期</th>
                      <th>是否离校</th>
                      <th>地址</th>
                      <th>离校时间</th>
                      <th>返校时间</th>
                      <th>联系人一</th>
                      <th>联系人二</th>
                      <th>交通方式</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
                console.log("获取到内容")
                console.log(res)
            }
        })
    }
}
function removeFrom() {
    $('#form').remove()
}
function doCgAdminPassword() {
    $.ajax({
        url:'/admin/cgAdminPassword',
        data:$('form').serialize(),
        success:()=>{
            alert("已修改")
        }
    })
}
function cgAdminPassword() {
    box.html(`
        <form onsubmit="return false">
            <div class="mb-3">
                <label for="account" class="form-label">账号</label>
                <input name="account" type="text" class="form-control" id="account" placeholder="请输入账号">
            </div>
            <div class="mb-3">
                <label for="oldPassword" class="form-label">旧密码</label>
                <input name="oldPassword" type="password" class="form-control" id="oldPassword" placeholder="请输入旧密码">
            </div>
            <div class="mb-3">
                <label for="newPassword" class="form-label">新密码</label>
                <input name="newPassword" type="password" class="form-control" id="newPassword" placeholder="请输入新密码">
            </div>
            <button type="button" class="btn btn-success" onclick="doCgAdminPassword()">修改密码</button>
        </form>
    `)
}



//登记信息管理
function sendToRecord(id) {
    $.ajax({
        url:'/admin/sendToRecord/'+id,
        success:function () {
            alert("已发布到学生")
            window.location.reload()
        }
    })
}
function delHolidayInformation(id) {
    $.ajax({
        url:'/admin/delHolidayInformation/'+id,
        success:function () {
            showHolidayInformation()
        }
    })
}


function doInsOrUpHolidayInformation() {
    $.ajax({
        url:'/admin/insOrUpHolidayInformation',
        data:$('form').serialize(),
        success:function () {
            showHolidayInformation()
        }
    })
}
function insOrUpHolidayInformation(id) {
    console.log(id)
    if (id!=0){
        console.log("执行更新操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="${id}">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期</span>
                    <input name="holiday" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期开始时间</span>
                    <input name="beginTime" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期截止时间</span>
                    <input name="endTime" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">开始填写时间</span>
                    <input name="beginRecord" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">截止填写时间</span>
                    <input name="endRecord" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>

                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="修改" onclick="doInsOrUpHolidayInformation()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }else {
        console.log("执行添加操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="0">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期</span>
                    <input name="holiday" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期开始时间</span>
                    <input name="beginTime" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期截止时间</span>
                    <input name="endTime" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">开始填写时间</span>
                    <input name="beginRecord" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">截止填写时间</span>
                    <input name="endRecord" type="datetime-local" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>

                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="添加" onclick="doInsOrUpHolidayInformation()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }
}
function showHolidayInformation(){
    $.ajax({
        url:'/admin/showHolidayInformation',
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].id}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><span class="badge bg-success">${res[i].beginTime}</span></td>
                      <td><span class="badge bg-success">${res[i].endTime}</span></td>
                      <td><span class="badge bg-success">${res[i].beginRecord}</span></td>
                      <td><span class="badge bg-success">${res[i].endRecord}</span></td>
                      <td><span class="badge bg-danger" onclick="sendToRecord(${res[i].id})">发布登记表</span></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary" onclick="insOrUpHolidayInformation(${res[i].id})"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow" onclick="delHolidayInformation(${res[i].id})"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                `
            }
            box.html(`
                <button class="btn-info" onclick="insOrUpHolidayInformation(0)">假期登记发布</button>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>编号</th>
                      <th>假期</th>
                      <th>假期开始时间</th>
                      <th>假期结束时间</th>
                      <th>开始填写时间</th>
                      <th>截止填写时间</th>
                      <th>设置</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}










//假期管理
function delHoliday(id) {
    $.ajax({
        url:'/admin/delHoliday/'+id,
        success:function () {
            showHoliday()
        }
    })
}


function doInsOrUpHoliday() {
    $.ajax({
        url:'/admin/insOrUpHoliday',
        data:$('form').serialize(),
        success:function () {
            showHoliday()
        }
    })
}
function insOrUpHoliday(id) {
    console.log("添加班级中")
    console.log(id)
    if (id!=0){
        console.log("执行更新操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input type="hidden" name="id" value="${id}">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期</span>
                    <input name="holiday" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="修改" onclick="doInsOrUpHoliday()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }else {
        console.log("执行添加操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="0">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">假期</span>
                    <input name="holiday" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>

                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="添加" onclick="doInsOrUpHoliday()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }
}
function showHoliday(){
    $.ajax({
        url:'/admin/showHoliday',
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].id}</span></td>
                      <td><span class="badge bg-success">${res[i].holiday}</span></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary" onclick="insOrUpHoliday(${res[i].id})"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow" onclick="delHoliday(${res[i].id})"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                `
            }
            box.html(`
                <button class="btn-info" onclick="insOrUpHoliday(0)">添加假期</button>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>编号</th>
                      <th>假期</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                    <tr>
                      <td><img class="avatar rounded-circle" src="assets/images/xs/avatar1.jpg" alt=""><span class="fw-bold ms-1">Joan Dyer</span></td>
                      <td><a href="projects.html">Box of Crayons</a></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}









/**
 * 学生信息管理
 * @param id
 */
function delStudent(id) {
    $.ajax({
        url:'/admin/delStudent/'+id,
        success:function () {
            showStudent()
        }
    })
}


function doInsOrUpStudent() {
    $.ajax({
        url:'/admin/insOrUpStudent',
        data:$('form').serialize(),
        success:function () {
            showStudent()
        }
    })
}
function insOrUpStudent(id) {
    console.log("添加班级中")
    console.log(id)
    if (id!=0){
        console.log("执行更新操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input type="hidden" name="id" value="${id}">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">姓名</span>
                    <input name="name" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">性别</span>
                    <input name="sex" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">专业</span>
                    <input name="specialized" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">电话号码</span>
                    <input name="telephone" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">班级</span>
                    <input name="stuClass" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">密码</span>
                    <input name="password" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="修改" onclick="doInsOrUpStudent()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }else {
        console.log("执行添加操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="0">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">姓名</span>
                    <input name="name" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">性别</span>
                    <input name="sex" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">专业</span>
                    <input name="specialized" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">电话号码</span>
                    <input name="telephone" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">班级</span>
                    <input name="stuClass" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">密码</span>
                    <input name="password" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" value="添加" onclick="doInsOrUpStudent()" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }
}
function showStudent(){
    $.ajax({
        url:'/admin/showStudent',
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].id}</span></td>
                      <td>${res[i].name}</td>
                      <td>${res[i].sex}</td>
                      <td><span class="badge bg-success">${res[i].specialized}</span></td>
                      <td>${res[i].telephone}</td>
                      <td>${res[i].stuClass}</td>
                      <td>${res[i].password}</td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary" onclick="insOrUpStudent(${res[i].id})"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow" onclick="delStudent(${res[i].id})"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                `
            }
            box.html(`
                <button class="btn-info" onclick="insOrUpStudent(0)">添加学生</button>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>编号</th>
                      <th>姓名</th>
                      <th>性别</th>
                      <th>专业</th>
                      <th>联系方式</th>
                      <th>班级</th>
                      <th>密码</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                    <tr>
                      <td><img class="avatar rounded-circle" src="assets/images/xs/avatar1.jpg" alt=""><span class="fw-bold ms-1">Joan Dyer</span></td>
                      <td><a href="projects.html">Box of Crayons</a></td>
                      <td><div class="avatar-list avatar-list-stacked px-3"><img class="avatar rounded-circle sm" src="assets/images/xs/avatar2.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar1.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar3.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar4.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar7.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar8.jpg" alt=""><span class="avatar rounded-circle text-center pointer sm" data-bs-toggle="modal" data-bs-target="#addUser"><i class="icofont-ui-add"></i></span></div></td>
                      <td><span class="badge bg-success">Working</span></td>
                      <td><span class="badge bg-success">Working</span></td>
                      <td><span class="badge bg-success">Working</span></td>
                      <td><span class="badge bg-success">Working</span></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}








/**
 * 班级管理
 * @param id
 */
function doInsOrUpClass(id) {
    $.ajax({
        url:'/admin/insOrUpClass',
        data:$('form').serialize(),
        success:function () {
            showClass()
        }
    })
}
function insOrUpClass(id) {
    console.log("添加班级中")
    console.log(id)
    if (id!=0){
        console.log("执行更新操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="${id}"/>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">姓名</span>
                    <input name="name" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">班级</span>
                    <input name="grade" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">专业</span>
                    <input name="specialized" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <input style="border-radius: 3px" type="button" onclick="doInsOrUpClass()" value="修改" class="btn-primary" />
                &nbsp;&nbsp;&nbsp;
                <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
        
            </form>
        </div>
        `)
    }else {
        console.log("执行添加操作")
        box.append(`
        <div id="form" style="background:white;position: absolute;left: 35%;top:35%;border: 1px solid burlywood;border-radius: 10px;padding: 10px">
            <form onsubmit="return false">
                <input name="id" type="hidden" value="0">
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">姓名</span>
                    <input name="name" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                        <span class="input-group-text" id="inputGroup-sizing-default">班级</span>
                    <input name="grade" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <span class="input-group-text" id="inputGroup-sizing-default">专业</span>
                    <input name="specialized" type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
                </div>
                <div class="input-group mb-3">
                    <input style="border-radius: 3px" type="button" onclick="doInsOrUpClass(0)" value="添加" class="btn-info" /> 
                    &nbsp;&nbsp;&nbsp;
                    <button style="border-radius: 3px" class="btn-danger" onclick="removeFrom()">取消</button>
                </div>
        
            </form>
        </div>
        `)
    }
}
function showClass(){
    $.ajax({
        url:'/admin/showClass',
        success:function (res) {
            let tbody=``;
            for (let i=0;i<res.length;i++){
                tbody+=`
                    <tr>
                      <td><span class="fw-bold ms-1">${res[i].id}</span></td>
                      <td>${res[i].name}</td>
                      <td>${res[i].grade}</td>
                      <td><span class="badge bg-success">${res[i].specialized}</span></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary" onclick="insOrUpClass(${res[i].id})"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow" onclick="delClass(${res[i].id})"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                `
            }
            box.html(`
                <button class="btn-info" onclick="insOrUpClass(0)">添加班级</button>
                <table id="myProjectTable" class="table table-hover align-middle mb-0" style="width:100%">
                  <thead>
                    <tr>
                      <th>编号</th>
                      <th>姓名</th>
                      <th>班级</th>
                      <th>专业</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${tbody}
                    <tr>
                      <td><img class="avatar rounded-circle" src="assets/images/xs/avatar1.jpg" alt=""><span class="fw-bold ms-1">Joan Dyer</span></td>
                      <td><a href="projects.html">Box of Crayons</a></td>
                      <td><div class="avatar-list avatar-list-stacked px-3"><img class="avatar rounded-circle sm" src="assets/images/xs/avatar2.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar1.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar3.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar4.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar7.jpg" alt=""><img class="avatar rounded-circle sm" src="assets/images/xs/avatar8.jpg" alt=""><span class="avatar rounded-circle text-center pointer sm" data-bs-toggle="modal" data-bs-target="#addUser"><i class="icofont-ui-add"></i></span></div></td>
                      <td><span class="badge bg-success">Working</span></td>
                      <td><div class="btn-group" role="group" aria-label="Basic outlined example">
                          <button type="button" class="btn btn-outline-secondary"><i class="icofont-edit text-success"></i></button>
                          <button type="button" class="btn btn-outline-secondary deleterow"><i class="icofont-ui-delete text-danger"></i></button>
                        </div></td>
                    </tr>
                  </tbody>
                </table>
            `)
            console.log("获取到内容")
            console.log(res)
        }
    })
}